package com.hmy.infrastructure.service.signature;

import com.hmy.infrastructure.api.bo.request.signature.SignatureBaseRequest;
import com.hmy.infrastructure.common.utils.SpringContextUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * @Description 电子签名服务基类
 * @Author seven.qi
 * @Date 2023/11/24 09:51
 * @Version 1.0
 */
@Slf4j
@Service
public class SignatureBaseService {
    private static final String service_suffix = "SignatureService";

    private static final String default_provider = "fadada";

    /**
     * 通过signatureBaseRequest.getProvider()获取对应的SignatureService的实现类
     *
     * @param signatureBaseRequest
     * @return
     */
    protected ISignatureService getSignatureService(SignatureBaseRequest signatureBaseRequest) {
        log.info("get signatureService by provider {}", signatureBaseRequest.getProvider());
        if (StringUtils.isEmpty(signatureBaseRequest.getProvider())) {
            log.info("provider is null, use default provider fadada");
            signatureBaseRequest.setProvider(default_provider);
        }
        ISignatureService bean = (ISignatureService) SpringContextUtil.getBean(signatureBaseRequest.getProvider() + service_suffix);
        log.info("get signatureService success, bean name is {}", bean.getClass().getSimpleName());
        return bean;
    }

}
